import {
  Body,
  Controller,
  Delete,
  Get,
  Param, ParseUUIDPipe,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
  RoleAdminAllDto,
  RoleAdminCreateDto,
  RoleAdminUpdateDto,
} from './role.dto';
import { RoleService } from './role.service';
import { AdminAuthGuard } from "@/common/auth/admin-auth.guard";
import {
  RoleAdminAllResult,
} from "@/module/role/role.result";

@Controller('/v1/admin/roles')
@ApiTags('Role_admin')
@UseGuards(AdminAuthGuard)
export class RoleV1AdminController {
  constructor(private readonly roleService: RoleService) {
  }

  @Get('/all')
  @ApiOperation({ summary: '全部' })
  @ApiOkResponse({ type: RoleAdminAllResult, isArray: true })
  async all(): Promise<RoleAdminAllResult[]> {
    const res = await this.roleService.adminAll();
    return res;
  }

  @Post('/')
  @ApiOperation({ summary: '新增' })
  async create(@Body() body: RoleAdminCreateDto): Promise<void> {
    await this.roleService.adminCreate(body);
    return;
  }

  @Patch('/:uuid')
  @ApiOperation({ summary: '修改' })
  async update(
    @Body() body: RoleAdminUpdateDto,
    @Param('uuid', ParseUUIDPipe) uuid: string,
  ): Promise<void> {
    await this.roleService.adminUpdate(body, uuid);
    return;
  }

  @Delete('/:uuid')
  @ApiOperation({ summary: '删除' })
  async destroy(@Param('uuid', ParseUUIDPipe) uuid: string): Promise<void> {
    await this.roleService.adminDestroy(uuid);
    return;
  }
}
